package com.example.ui_test.adapter

import android.animation.ArgbEvaluator
import android.graphics.Color
import androidx.core.graphics.ColorUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.ui_test.R
import com.example.ui_test.bean.ColorBean

/**
 *
 * @author zgl
 * 日期：2023/8/10
 * 时间：16:41
 *
 */
class ColorAdapter(layoutResId: Int, mList: ArrayList<ColorBean>?) :
    BaseQuickAdapter<ColorBean, BaseViewHolder>(layoutResId, mList) {

    val argbEvaluator = ArgbEvaluator()

    override fun convert(holder: BaseViewHolder, item: ColorBean) {
        val num = item.num

        val color = if (num > 100) {
            argbEvaluator.evaluate(
                (num - 100) / 100,
                Color.GREEN,
                Color.RED
            ) as Int
        } else {
            argbEvaluator.evaluate(
                num / 100,
                Color.BLUE,
                Color.GREEN
            ) as Int
        }
        holder.setBackgroundColor(R.id.fl, color)
        holder.setText(R.id.tv, "${(num * 10).toInt() / 10f}")
    }
}